package cn.zhonghuanzhiyuan.sprc.basicinfo.controller;

import cn.org.bachelor.web.json.JsonResponse;

import cn.zhonghuanzhiyuan.sprc.basicinfo.domain.SafeDeviceOverhaul;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.*;
import cn.zhonghuanzhiyuan.sprc.basicinfo.service.SafeDeviceOverhaulService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业装置大修(SafeDeviceOverhaul)控制层
 *
 * @author david
 * @since 2024-02-27 21:19:28
 */
@Api(tags = "企业装置大修控制层")
@RestController
@RequestMapping("/safeDeviceOverhaul")
@CrossOrigin // 线上不需要 （要注掉）
public class SafeDeviceOverhaulController {
    /**
     * 服务对象
     */
    @Autowired
    private SafeDeviceOverhaulService safeDeviceOverhaulService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "获取企业装置大修单条数据")
    @GetMapping("/getSafeDeviceOverhaulById/{id}")
    public HttpEntity<JsonResponse> getSafeDeviceOverhaulById(@ApiParam(name = "id", value = "编号", required = true) @PathVariable String id) {
        SafeDeviceOverhaul safeDeviceOverhaul = safeDeviceOverhaulService.getSafeDeviceOverhaulById(id);
        return JsonResponse.createHttpEntity(safeDeviceOverhaul, HttpStatus.OK);
    }

    /**
     * 分页查询
     *
     * @param querySafeDeviceOverhaulVo
     * @return PageInfo<SafeDeviceOverhaul>
     */
    @ApiOperation(value = "获取企业装置大修分页数据")
    @PostMapping("/getSafeDeviceOverhaulPage")
    public HttpEntity<JsonResponse> getSafeDeviceOverhaulPage(@ApiParam(name = "querySafeDeviceOverhaulVo", value = "企业装置大修", required = true) @RequestBody QuerySafeDeviceOverhaulVo querySafeDeviceOverhaulVo) {
        PageHelper.startPage(querySafeDeviceOverhaulVo.getPageNum(), querySafeDeviceOverhaulVo.getPageSize());
        List<SafeDeviceOverhaul> list = safeDeviceOverhaulService.selectSafeDeviceOverhaulList(querySafeDeviceOverhaulVo);
        return JsonResponse.createHttpEntity(new PageInfo<>(list), HttpStatus.OK);
    }

    /**
     * 导出查询
     *
     * @param querySafeDeviceOverhaulVo
     * @return SafeDeviceOverhaul
     */
    @ApiOperation(value = "获取企业装置大修导出数据")
    @PostMapping("/getSafeDeviceOverhaulList")
    public HttpEntity<JsonResponse> getSafeDeviceOverhaulList(@ApiParam(name = "querySafeDeviceOverhaulVo", value = "企业装置大修", required = true) @RequestBody QuerySafeDeviceOverhaulVo querySafeDeviceOverhaulVo) {
        List<SafeDeviceOverhaul> list = safeDeviceOverhaulService.selectSafeDeviceOverhaulList(querySafeDeviceOverhaulVo);
        return JsonResponse.createHttpEntity(list, HttpStatus.OK);
    }

    /**
     * 新增或保存
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改或新增企业装置大修")
    @PostMapping("/updateOrSaveSafeDeviceOverhaul")
    public HttpEntity<JsonResponse> updateOrSaveSafeDeviceOverhaul(@ApiParam(name = "updateOrSaveSafeDeviceOverhaulVo", value = "企业装置大修", required = true) @RequestBody UpdateOrSaveSafeDeviceOverhaulVo updateOrSaveSafeDeviceOverhaulVo) {
        safeDeviceOverhaulService.insertOrUpdate(updateOrSaveSafeDeviceOverhaulVo);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除企业装置大修")
    @DeleteMapping("/deleteSafeDeviceOverhaulByIds/{ids}")
    public HttpEntity<JsonResponse> deleteSafeDeviceOverhaulByIds(@ApiParam(name = "idList", value = "主键集合", required = true) @PathVariable String ids) {
        safeDeviceOverhaulService.deleteByIds(ids);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }

}
